package drds.server.sqlparser.sqlobject.statement.query;

import drds.server.sqlparser.sqlobject.AbstractSqlObject;
import drds.server.sqlparser.visitor.Visitor;

/**
 * 子查询
 * 
 * @author 曹正辉<330937205@qq.com>
 * 
 */
public class SubQuery extends AbstractSqlObject {

	protected IQuery iQuery;

	public SubQuery() {

	}

	public SubQuery(IQuery iQuery) {
		this.setQuery(iQuery);
	}

	public void setQuery(IQuery iQuery) {
		if (iQuery != null) {
			iQuery.setParent(this);
		}
		this.iQuery = iQuery;
	}

	public IQuery getIQuery() {
		return this.iQuery;
	}

	protected void accept0(Visitor visitor) {
		if (visitor.visit(this)) {
			acceptChild(visitor, this.iQuery);
		}

		visitor.endVisit(this);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((iQuery == null) ? 0 : iQuery.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null)
			return false;
		if (getClass() != o.getClass())
			return false;
		SubQuery other = (SubQuery) o;
		if (iQuery == null) {
			if (other.iQuery != null)
				return false;
		} else if (!iQuery.equals(other.iQuery))
			return false;
		return true;
	}

}
